<?php

namespace app\admin\controller;

use app\common\model\ShopMemberCard;
use app\common\model\ShopStore;
use app\common\service\Status;
use buildView\Button;
use buildView\Detail;
use buildView\Actions;
use buildView\Filter;
use think\Controller;
use buildView\Grid;
use app\common\model\ApplyJoin;

/**
 * 申请入驻
 * Class ApplyAdd
 * @package app\admin\controller
 */
class ApplyAdd extends Controller
{
    /**
     * 列表
     * @auth true
     * @menu true
     * @return string
     */
    public function index()
    {
        $grid = new Grid(new ApplyJoin);
        $grid->hideExportButton();
        $grid->hideAddButton();
        $grid->hideDeletesButton();
        // $grid->actions(function ($action, $data) {
        $grid->actions(function ($action, $data) {
            $action->hideEdit();
            $action->hideDel();
            
            if($data['pass'] == 0){
                $button1 = new Button('通过');
                $button1->save($data['id'], ['pass' => 1], url('passActivity'), '确认通过审核？');
                $action->append($button1);
            }
        });
        $grid->filter(function ($filter){
            $filter->like('username','昵称');
            $filter->like('name','姓名');
            $filter->like('phone','电话号码');
            $filter->like('store','门店名称');
            $filter->dateBetween('create_at','添加时间');
            $filter->eq('pass', '订单状态')->select(Status::ISPASS());
        });
        $grid->username('昵称');
        $grid->name('姓名');
        $grid->phone('手机号码');
        $grid->store('门店名称');
        $grid->address('门店地址');
        $grid->pass('订单状态')->display(function ($val,$dat,$html){
            if($html == 0){
                $html = "<span style='background-color: #fa3512;color:#FFF;padding:3px;border-radius: 2px;'>未通过</span>";
                return $html;
            }elseif ($html == 1) {
                $html = "<span style='background-color: #1bd030;color:#FFF;padding:3px;border-radius: 2px;'>已通过</span>";
                return $html;
            }
        });
        $grid->create_time('创建时间');
        
        return $grid->view();
    }
    
    
    /**
     * 详情
     * @auth true
     * @menu true
     * @return string
     */
    public function detail()
    {
        $detail = new Detail(new ApplyJoin);
        $detail->layout('基本信息', 6, function ($detail) {
            $detail->username('昵称');
            $detail->name('姓名');
            $detail->phone('手机号码');
            $detail->store('门店名称');
            $detail->address('门店地址');
            $detail->create_time('创建时间');
        });
        $detail->layout('门店图片', 6, function ($detail) {
            $detail->imgList('门店图片')->display(function ($val, $data, $html){
                $string = str_replace("'",'"', $data['imgList']);
                $arr = json_decode($string,true);
                return "<img src='".$arr[0]['src']."'/>";
            });
        });
        $detail->layout('营业执照', 6, function ($detail) {
            $detail->Y_Img('营业执照')->display(function ($val, $data, $html){
                $string = str_replace("'",'"', $data['Y_Img']);
                $arr = json_decode($string,true);
                return "<img src='".$arr[0]['src']."'/>";
            });
            // $detail->Y_Img('营业执照')->image(0,150,50);
        });
         $detail->layout('身份证图片', 6, function ($detail) {
            $detail->idCart01('正面')->display(function ($val, $data, $html){
                $string = str_replace("'",'"', $data['idCart01']);
                $arr = json_decode($string,true);
                return "<img src='".$arr[0]['src']."'/>";
            });
            $detail->idCart02('背面')->display(function ($val, $data, $html){
                $string = str_replace("'",'"', $data['idCart02']);
                $arr = json_decode($string,true);
                return "<img src='".$arr[0]['src']."'/>";
            });
        });
        return $detail->view();
    }
    public function passActivity (){
        $id = $this->request->post('id',0);
        $pass = $this->request->post('pass');
        $res = ApplyJoin::where('id', $id)->update(['pass' => $pass]);
        $this->success('成功','');
    }
}
